package com.hyw.supply.config;

import com.alibaba.druid.pool.DruidDataSource;
import lombok.extern.java.Log;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.CommandLineRunner;
import org.springframework.stereotype.Component;

import javax.sql.DataSource;

@Component
@Log
public class MyStartupRunner implements CommandLineRunner {


    @Autowired
    private DataSource dataSource;
    @Override
    public void run(String... args) throws Exception {
        // 在这里执行启动后的任务
        otherLoadingConfig();
    }

    private  void otherLoadingConfig() {

        // 确保注入的DataSource是DruidDataSource类型
        assert dataSource instanceof DruidDataSource;

        // 可以进一步通过DruidDataSource的方法获取配置详情进行验证
        DruidDataSource druidDataSource = (DruidDataSource) dataSource;
        // 例如，检查初始化大小

        log.info("初始化大小"+druidDataSource.getInitialSize());
        // 检查

        log.info("最大活跃连接数"+druidDataSource.getMaxActive());
        // 等等...

        System.out.println("Druid数据库连接池配置生效");
    }
}

